from werkzeug.security import generate_password_hash, check_password_hash
from app.models.user import User


class UserRepository:
    def __init__(self):
        self.users = [
            User(1, "Alice", "alice@example.com", generate_password_hash("alice123")),
            User(2, "Bob", "bob@example.com", generate_password_hash("bob123"))
        ]

    def find_by_email(self, email):
        return next((u for u in self.users if u.email == email), None)

    def create_user(self, name, email, password):
        new_user = User(len(self.users) + 1, name, email, generate_password_hash(password))
        self.users.append(new_user)
        return new_user
